<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Model;

trait HasSnAttribute
{
    protected static function bootHasSnAttribute()
    {
        static::creating(function(Model $model) {
            if (\Schema::hasColumn($model->getTable(), $model->snable_column_name())) {
                $model->setAttribute('sn', generate_sn($model->snable_prefix()));
            }
        });
    }

    protected function snable_column_name():string {
        return 'sn';
    }

    protected function snable_prefix():string {
        return '';
    }
}
